<template>
  <div class="goods">
    <!-- 商品列表 -->
    <!-- 以前的路由方式   标签跳转 -->
    <!-- <router-link :to="'/goodslist/goodsinfo/' + item.id" class="goodsitem" v-for="item in goodslist" :key="item.id">
      <img :src="item.img_url" alt="">
      <h1 class="goodstitle">{{item.title}}</h1>
      <div class="goodsinfo">
        <p class="price">
          <span class="now">￥{{item.sell_price}}</span>
          <span class="old">￥{{item.market_price}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩余:{{item.stock_quantity}}件</span>
        </p>
      </div>
    </router-link> -->
    <!-- 现在使用导航式编程   window.location.href -->
    <div class="goodsitem" v-for="item in goodslist" :key="item.id" @click="togoodsinfo(item.id)">
      <img :src="item.img_url" alt="">
      <h1 class="goodstitle">{{item.title}}</h1>
      <div class="goodsinfo">
        <p class="price">
          <span class="now">￥{{item.sell_price}}</span>
          <span class="old">￥{{item.market_price}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩余:{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>

    <!-- 加载更多 -->
    <mt-button type="danger" size="large"  @click="goodsmore">加载更多</mt-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      pageindex:1,
      goodslist:[],
    };
  },
  created(){
    this.getgoodlist()
  },
  methods:{
    getgoodlist(){
      this.$http.get('api/getgoods'+'?pageindex='+this.pageindex).then((res)=>{
        // console.log(res.body)
        if(res.body.status === 0){
          this.goodslist =  this.goodslist.concat(res.body.message)
        }
      })
    },
    goodsmore(){
      this.pageindex++;
      this.getgoodlist()
    },
    togoodsinfo(id){
      this.$router.push({name:'goodsinfo',params:{ id:id } })
    }
  }
}
</script>
<style lang="scss" scoped>
.goods{
 display: flex;
 justify-content: space-between;
 flex-wrap: wrap;
 padding: 5px;
}
  .goodsitem{
    width: 49%;
   padding: 1px;
   background-color: #eee;
   margin-bottom: 5px;
   box-shadow: 0 0 8px #ccc;

   display: flex;
   flex-direction: column;
   justify-content: space-between;
    img{
      width: 100%;
    }
    .goodstitle{
      font-size: 14px;
      padding: 2px;
      color: #000;
    }
    .goodsinfo{
      .price{
        .now{
          color: red;
          font-weight: 700;
          font-size: 16px;
        }
        .old{
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .sell{
        display: flex;
        justify-content: space-between;
      }
    }
  }
</style>